home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / whisper / source / cons.asm < prev    next >
Encoding:
Assembly Source File  |  1991-10-19  |  4.6 KB  |  278 lines

  1. rmcode    segment word public use16
  2. rmcode    ends
  3. rmdata    segment dword public 'DATA' use16
  4. rmdata    ends
  5. pmdata    segment dword public 'DATA' use32
  6. pmdata    ends
  7. pmcode    segment dword public 'CODE' use32
  8. pmcode    ends
  9. DGROUP    group    rmdata,pmdata
  10.  
  11. CONBIOS        equ    29h
  12. STACK_SIZE    equ    (8*1024)    ; !!! Check of Size !!!
  13.  
  14. extrn    cons_bios:near            ; Consol Bios "C" Funcsion
  15.  
  16. ;**********************************************
  17. ;
  18. ;    Real Mode Data Segment defs
  19. ;
  20. ;**********************************************
  21. rmdata    segment 
  22. rmdata    ends
  23.  
  24. ;**********************************************
  25. ;
  26. ;    Real Mode Code Segment Funcsion
  27. ;
  28. ;**********************************************
  29. rmcode    segment word public use16
  30.     assume    cs:rmcode,ds:DGROUP
  31.  
  32. in_dos_call    proc    far
  33.  
  34.     mov    ah,34h
  35.     int    21h
  36.     mov    ax,es
  37.     ret
  38.  
  39. in_dos_call    endp
  40.  
  41. rmcode    ends
  42.  
  43. ;**********************************************
  44. ;
  45. ;    Protect Mode Data Segment defs
  46. ;
  47. ;**********************************************
  48. pmdata    segment
  49.  
  50. nt_vet_off    dd    ?    ; offset +
  51. nt_vet_seg    dw    ?    ; segment = pword !!
  52. rl_vet_ral    dd    ?
  53.  
  54. save_esp    dd    ?    ; offset +
  55. save_ss        dw    ?    ; segment = pword !!
  56.  
  57. stack_flg    dw    0    ; stack access flg
  58.  
  59. new_esp        dd    ?    ; offset +
  60. new_ss        dw    ?    ; segment = pword !!
  61.  
  62.         public    in_dos_adr
  63. in_dos_adr    dd    0    ; in dos flg in MS-DOS 1M Selecter
  64.  
  65. consol_path    db    "CON",0
  66. null_path    db    "NUL",0
  67.  
  68.         align    4            ; align set
  69. local_stack    db    STACK_SIZE dup(?)    ; local stack era
  70. local_stack_btm    dw    ?            ; dummy
  71.  
  72. pmdata    ends
  73.  
  74. ;**********************************************
  75. ;
  76. ;    Protect Mode Code Segment Funcsion
  77. ;
  78. ;**********************************************
  79. pmcode    segment
  80.     assume    cs:pmcode,ds:DGROUP
  81.  
  82. ;***************************************************
  83. ;    Consol Bios Old Vectror ReSet
  84. ;
  85. ;void    cons_bios_ret(void)
  86. ;
  87. ;call to void cons_bios(struct reg *rp)
  88. ;***************************************************
  89. cons_bios_entry    proc    far
  90.     cmp    stack_flg,0
  91.     jne    short go_ret
  92.     inc    stack_flg
  93.  
  94.     mov    save_esp,esp        ; save ss:esp 
  95.     mov    save_ss,ss
  96.     lss    esp,pword ptr new_esp     ; Load Loacl Stack Address
  97.     pushad
  98.  
  99.     sti
  100.     cld
  101.  
  102.     push    ds
  103.     pop    es
  104.     mov    ebp,esp
  105.     push    ebp
  106.     call    cons_bios
  107.     add    esp,4
  108.  
  109.     popad
  110.     lss    esp,pword ptr save_esp
  111.  
  112.     dec    stack_flg
  113. go_ret:    iretd
  114.  
  115. cons_bios_entry    endp
  116.  
  117. ;************************************
  118. ; File I/O ReDirect Asm Call onry!
  119. ;************************************
  120. reopen    proc    near
  121.     push    ax
  122.     mov    ah,3Eh        ; close
  123.     int    21h
  124.     pop    ax
  125.     mov    ah,3Dh        ; open file
  126.     int    21h
  127. reo_ret:ret
  128.  
  129. reopen    endp
  130.  
  131. ;***************************************************
  132. ;    Consol Bios Entry SetUp
  133. ;
  134. ;void    cons_bios_set(void)
  135. ;***************************************************
  136.     public    cons_bios_set
  137. cons_bios_set    proc    near
  138.  
  139.     push    ds
  140.     push    es
  141.     push    ebx
  142.     push    edx
  143.  
  144.     mov    ax,2502h        ; get neitive int vect
  145.     mov    cl,CONBIOS
  146.     int    21h
  147.     mov    nt_vet_seg,es
  148.     mov    nt_vet_off,ebx
  149.  
  150.     mov    ax,2503h
  151.     mov    cl,CONBIOS
  152.     int    21h
  153.     mov    rl_vet_ral,ebx
  154.  
  155.     mov    ax,2506h
  156.     mov    cl,CONBIOS
  157.     push    ds
  158.     mov    dx,cs
  159.     mov    ds,dx
  160.     lea    edx,cons_bios_entry
  161.     int    21h
  162.     pop    ds
  163.  
  164.     mov    new_ss,ds
  165.     lea    ebx,local_stack_btm
  166.     mov    new_esp,ebx
  167.  
  168.     mov     al,0
  169.     mov     bx,0
  170.     lea     edx,consol_path
  171.     call    reopen
  172.     mov     al,1
  173.     mov     bx,1
  174.     call    reopen
  175.     mov     al,1
  176.     mov     bx,2
  177.     call    reopen
  178.  
  179.     pop    edx
  180.     pop    ebx
  181.     pop    es
  182.     pop    ds
  183.     ret
  184.  
  185. cons_bios_set    endp
  186.  
  187. ;***************************************************
  188. ;    Consol Bios Old Vectror ReSet
  189. ;
  190. ;void    cons_bios_ret(void)
  191. ;***************************************************
  192.     public    cons_bios_ret
  193. cons_bios_ret    proc    near
  194.  
  195.     push    ds
  196.     push    ebx
  197.     push    edx
  198.  
  199.     mov    cl,CONBIOS
  200.     mov    ebx,rl_vet_ral
  201.     mov    edx,nt_vet_off
  202.     mov    ax,nt_vet_seg
  203.     push    ds
  204.     mov    ds,ax    
  205.     mov    ax,2507h
  206.     int    21h
  207.     pop    ds
  208.  
  209.     mov    al,0
  210.     mov    bx,0
  211.     lea    edx,null_path
  212.     call    reopen
  213.     mov    al,1
  214.     mov    bx,1
  215.     call    reopen
  216.     mov    al,1
  217.     mov    bx,2
  218.     call    reopen
  219.  
  220.     pop    edx
  221.     pop    ebx
  222.     pop    ds
  223.     ret
  224.  
  225. cons_bios_ret    endp
  226.  
  227. ;***************************************************
  228. ;    MS-DOS Funcsion Call Check!
  229. ;
  230. ;ont    in_dos_check(void)
  231. ;***************************************************
  232.     public    in_dos_check
  233. in_dos_check    proc    near
  234.     push    ds
  235.     push    edi
  236.  
  237.     cmp    in_dos_adr,0
  238.     jne    indos1
  239.  
  240.     pushad
  241.     push    ds
  242.     push    es
  243.  
  244.     mov    ax,250Fh
  245.     push    ds
  246.     pop    es
  247.     lea    ebx,in_dos_call
  248.     mov    ecx,0
  249.     int    21h
  250.  
  251.     mov    ax,250Eh
  252.     mov    ebx,ecx            ; real address
  253.     mov    ecx,0            ; stack data = 0
  254.     int    21h
  255.  
  256.     pop    es
  257.     pop    ds
  258.     movzx    eax,ax
  259.     shl    eax,4
  260.     movzx    ebx,bx
  261.     add    eax,ebx            ; seg >> 4 | off
  262.     mov    in_dos_adr,eax
  263.     popad
  264.  
  265. indos1:    mov    edi,in_dos_adr
  266.     mov    ax,0060h        ; MS-DOS 1M Real Selecter
  267.     mov    ds,ax
  268.     movzx    eax,byte ptr [edi]
  269.     pop    edi
  270.     pop    ds
  271.     ret
  272.  
  273. in_dos_check    endp
  274.  
  275. pmcode    ends
  276.  
  277.     end
  278.